# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： tmp
Description :
Author : 'li'
date： 6/4/2024
-------------------------------------------------
Change Activity:
6/4/2024:
-------------------------------------------------
"""
from ll.utils.network.ip_re import is_ipv4


class CliParser:
    def __init__(self, cmd_result):
        """

        Args:
            cmd_result:
        """
        self.cmd_result = cmd_result
        self.error_result = []

    @staticmethod
    def _get_items(line):
        line = line.strip()
        items = line.split(' ')
        return items

    def _get_error_ip(self):
        error_ip_lst = []
        normal_ip_lst = []
        lines = self.cmd_result.split('\n')
        for line in lines:
            items = self._get_items(line)
            ip_str = items[0]
            if not is_ipv4(ip_str):
                continue
            if 'Established' in line:
                normal_ip_lst.append(ip_str)
            else:
                error_ip_lst.append(ip_str)
        return normal_ip_lst, error_ip_lst

    def __call__(self):
        """

        Returns:

        """
        return self._get_error_ip()
